// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CopyOnPremisesStepTest.cs" company="">
//   
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace Tests
{
    using System;
    using System.IO;
    using System.Threading;

    using ExecutionTool.CopyDatabase;
    using ExecutionTool.CopyOnPremises;
    using ExecutionTool.ImportExport;
    using ExecutionTool.Profile;

    using Microsoft.Practices.EnterpriseLibrary.Logging;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using Moq;

    [TestClass]
    public class CopyOnPremisesStepTest
    {
        #region Fields

        private Profile profile;

        #endregion

        #region Public Methods and Operators

        [TestMethod]
        [Ignore]
        public void IntegrationTest()
        {
            var loggerMock = new Mock<LogWriter>();
            var step = new CopyOnPremisesStep(
                this.profile, 
                new ExportStepInfo(
                    Guid.NewGuid(), "bacpac/SMSMarketingDB-Thursday.bacpac", 19939895, new SqlAzureDatabaseInfo(SqlAzureDatabaseEdtion.Web, 1)), 
                new StorageAdapter(loggerMock.Object), 
                new OnPremisesAdapter(loggerMock.Object), 
                loggerMock.Object);

            var e2 = new ManualResetEvent(false);
            step.Progressed += (sender, args) => Console.WriteLine("Progress: {0}%.", args.Progress);
            step.Faulted += (sender, args) =>
                {
                    Console.WriteLine(args.Exception);
                    e2.Set();
                };
            step.Finished += (sender, args) =>
                {
                    Console.WriteLine(step.GetProgress());
                    e2.Set();
                };
            step.Start();

            e2.WaitOne();
        }

        [TestInitialize]
        public void Setup()
        {
            this.profile = new Profile
                {
                    TargetAzureStorage =
                        new AzureStorageLocation
                            {
                                StorageAccount = "dataprotectorpoc", 
                                AccessKey = "Oz8JVCBWmDvJBoIIiKVCLtzapCeHo7ZaV5Edvfq7Jl7NeUGjkCyUGV4gKmjLB6/Wq6dpDMdKtRbdj31mKIx7DQ==", 
                            }, 
                    TargetOnPremisesLocation = new OnPremisesLocation { Location = @"\\jackma\temp" }
                };
        }

        [TestMethod]
        [Ignore]
        public void TestOnPremisesFileSize()
        {
            var info = new FileInfo(@"\\jackma\temp\SMSMarketingDB-Thursday.bacpac");
            Console.WriteLine(info.Length);
        }

        [TestMethod]
        public void TestPathCombine()
        {
            var folder = @"\\jackma\temp";
            var file = @"bacpac";

            var result = Path.Combine(folder, file);

            Console.WriteLine(result);
        }

        #endregion
    }
}
